package com.example.springboot.jpa.usermanager.service;

import com.example.springboot.jpa.usermanager.dao.RoleDao;
import com.example.springboot.jpa.usermanager.entity.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleDao roleDao;

	@Transactional
	@Override
	public int insert(Role role) {
//		测试事物是否起作用，如果没有保存成功，则事物生效
//		int a = 1/0;
		Role obj = roleDao.save(role);
		System.out.println(obj);
		return 1;
	}

	@Transactional
	@Override
	public int deleteById(Integer id) {
		roleDao.delete(id);
		return 1;
	}

	@Transactional
	@Override
	public int update(Role role) {
		roleDao.save(role);
		return 1;
	}

	@Override
	public Role getById(Integer id) {
		return roleDao.getOne(id);
	}

}